package cn.play.cardgame.base;

import android.content.Intent;
import android.os.Bundle;
import butterknife.ButterKnife;

/**
 * Created by renlei on 2016/5/23.
 */
public abstract class AppActivity extends BaseActivity {

	// 获取第一个fragment
	protected abstract BaseFragment getFirstFragment();

	// 获取Intent
	protected void handleIntent(Intent intent) {

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(getContentViewId());
		ButterKnife.inject(this);

		if (null != getIntent()) {
			handleIntent(getIntent());
		}
		// 避免重复添加Fragment
		if (null == getSupportFragmentManager().getFragments()) {
			BaseFragment firstFragment = getFirstFragment();
			if (null != firstFragment) {
				addFragment(firstFragment);
			}
		}

		ActivityManager.getInstance().addActivity(this);
	}

	@Override
	protected int getContentViewId() {
		return 0;
	}

	@Override
	protected int getFragmentContentId() {
		return 0;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		ActivityManager.getInstance().finishActivity(this);
	}
}
